package com.seven.service;

import java.util.List;

import com.seven.dao.UsersDao;
import com.seven.entity.Users;
//普通用户业务类

public class UsersService {
	
	UsersDao usersDao = new UsersDao();
	/**
	 * 添加用户
	 */
	public int addUsers(Users users) {		
		return usersDao.addUsers(users);	
	}
	
	/**
	 * 更新用户
	 */
	public int updateUsers(Users users) {
		return usersDao.updateUsers(users);
	}
	
	/**
	 * 给用户加积分
	 */
	public int addscore(Users users) {
		int users_id = users.getUsers_id();
		
		List<Users> list = usersDao.selectById(users_id);
		Users users2 = list.get(0);
		
		String users_name = users2.getUsers_name();
		String users_password = users2.getUsers_password();
		int users_score = users2.getUsers_score()+1;
		String users_username = users2.getUsers_username();
		
		Users users3 = new Users();
		users3.setUsers_id(users_id);
		users3.setUsers_name(users_name);
		users3.setUsers_password(users_password);
		users3.setUsers_score(users_score);
		users3.setUsers_username(users_username);
		
		
		
		return usersDao.updateUsers(users3);
	}
	
	/**
	 * 查询所有用户
	 */
	public List<Users> selectAllUsers() {
		return usersDao.selectAllUsers();
		
	}
	
	/**
	 * 通过账号查询用户
	 */
	public List<Users> selectByUsers_username(Users users) {
		return usersDao.selectByUsers_username(users);
		
	}
	
	/**
	 * 通过id查姓名
	 */
	public String selectNameById(int users_id){
		
		List<Users> list = usersDao.selectNameById(users_id);
		Users users = list.get(0);
		return users.getUsers_name();
		
	}
}
